#!/bin/sh

# start/stop/restart/reload cfenvd

# Start cfenvd:
cfenvd_start() {
  if [ -x /usr/sbin/cfenvd ]; then
    echo "Starting the CFEengine environment service:  /usr/sbin/cfexecd"
    /usr/sbin/cfenvd
  fi
}

# Stop cfenvd:
cfenvd_stop() {
  /bin/killall cfenvd 2> /dev/null
}

# Restart cfenvd:
cfenvd_restart() {
  cfenvd_stop
  sleep 1
  cfenvd_start
}

# Reload cfenvd:
cfenvd_reload() {
  /bin/killall -HUP cfenvd
}

case "$1" in
'start')
  cfenvd_start
  ;;
'stop')
  cfenvd_stop
  ;;
'restart')
  cfenvd_restart
  ;;
'reload')
  cfenvd_reload
  ;;
*)
  echo "usage $0 start|stop|restart|reload"
esac
